<?php
namespace Admin\Controller;

class UserController extends Controller {

    public function getByUserName() {
        $name = I('get.name', '');

        if(empty($name)) {
            showJson(array('s' => false, 'm' => '请输入会员名称'));
        }

        $m     = D2();
        $field = array('uid', 'user_name', 'type', 'status');

        $r = ($_d = $m->field($field)->getByUserName($name))
             ? array('s' => true, 'd' => $_d)
             : array('s' => false, 'm' => '没有找到会员信息');

        showJson($r);
    }

    /**
     * checkExistsByUserName
     * 根据用户名检测会员是否存在
     *
     * @return void
     */
    public function isExistsByUserName() {
        $name = I('get.user_name', '');

        if(empty($name)) {
            showJson(array('s' => false, 'm' => '会员不存在'));
        }

        $msg = D2()->getByUserName($name) ? array('s' => true, 'm' => '会员存在') : array('s' => false, 'm' => '会员不存在');

        showJson($msg);
    }

    public function checkExistsName() {
        $this->isExistsByUserName();
    }

    public function switchTo() {
        $id = I('get.id', 0, 'intval');

        if(empty($id)) {
            throw new \Exception('参数不完整，无法进行后续操作');
        }

        D2()->switchToById($id);
    }

}
